package com.alibaba.citrus.cr.mn.order.center.forecastorder.event;

import com.alibaba.citrus.cr.mn.order.center.forecastorder.service.ForecastOrderBizWriteService;
import com.alibaba.cz.base.tool.log.Log;
import com.alibaba.fastjson.JSON;
import com.epoch.app.mnordercenter.model.dto.ConfirmReplyRequest;
import org.springframework.context.ApplicationListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
@EnableAsync
public class ForecastConfirmListener implements ApplicationListener<ForecastConfirmEvent> {
    private static final Log log = Log.getLogger(ForecastConfirmListener.class);

    @Resource
    private ForecastOrderBizWriteService forecastOrderBizWriteService;

    @Async("eventTaskExecutor")
    @Override
    public void onApplicationEvent(ForecastConfirmEvent event) {
        ConfirmReplyRequest source = (ConfirmReplyRequest) event.getSource();
        log.info("预报订单确认事件入参:{}", JSON.toJSONString(source));
        forecastOrderBizWriteService.batchConfirm(source);
    }
}
